package com.example.homework20230224;

import com.sun.org.apache.bcel.internal.classfile.Code;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class B extends JFrame implements ActionListener {
    private JLabel label1, label2;
    private JTextField userName;// 用户名
    private JPasswordField password;// 密码输入框
    private JButton button1, button2;

    public B() {
        getContentPane().setLayout(new BorderLayout(0, 0));
        JPanel panel = new ImagePanel();
        getContentPane().add(panel);
        // 设置panel的布局方式为null
        panel.setLayout(null);
        // 添加两个“用户名”“密码”的label，通过字体的大小更改label的大小
        label1 = new JLabel("用户名");
        label1.setFont(new Font("宋体", Font.BOLD, 26));
        label1.setForeground(Color.yellow);
        label1.setBounds(475, 350, 100, 50);
        label2 = new JLabel("密  码");
        label2.setFont(new Font("宋体", Font.BOLD, 26));
        label2.setForeground(Color.yellow);
        label2.setBounds(475, 430, 100, 50);

        // 添加两个输入框，用于输入用户名和密码。用户名用JTextFied，密码用JPasswordField
        userName = new JTextField(10);
        userName.setBounds(575, 350, 200, 50);
        userName.setFont(new Font("宋体", Font.BOLD, 20));
        userName.setColumns(15);

        password = new JPasswordField(10);
        password.setBounds(575, 430, 200, 50);
        password.setFont(new Font("宋体", Font.BOLD, 30));
        password.setColumns(15);

        // 添加两个按钮，用于显示登录和注销功能！！
        button1 = new JButton("登陆");
        button1.setFont(new Font("宋体", Font.BOLD, 26));
        button1.setForeground(Color.black);
        button1.setBounds(555, 530, 100, 50);
        button1.addActionListener(this);


        button2 = new JButton("注册");
        button2.setFont(new Font("宋体", Font.BOLD, 26));
        button2.setForeground(Color.black);
        button2.setBounds(700, 530, 100, 50);
        button2.addActionListener(this);

        // 添加所需组件
        panel.add(label1);
        panel.add(userName);
        panel.add(label2);
        panel.add(password);
        panel.add(button1);
        panel.add(button2);
    }

    public static void main(String args[]) {
        // new一个新的窗口，窗口是在构造器中生成的，而JApplet可以在init()方法里初始化，注意这两者的区别
        B frame = new B();
        frame.setSize(900, 700);// 窗体大下
        frame.setLocation(100, 100);// 窗口初始位置
        frame.setResizable(false);// 不可更改窗体大小
        frame.setTitle("银行账户管理系统");
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);// 默认关闭方式
        frame.setVisible(true);// 窗口可见


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==button1){
            String s1=userName.getText();
            String s2=new String(password.getPassword());

        }
        if(e.getSource()==button2){
            userName.setText("");
            password.setText("");
        }
    }

    class ImagePanel extends JPanel {
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            ImageIcon icon = new ImageIcon("src/image/Ship.jpg");
            g.drawImage(icon.getImage(), 0, 0, null);
        }
    }

}

